#include "pcfdata.h"
#include "../logs/printlog.h"

#if PCF_TEST
#include<wiringPi.h>

#include <wiringPiI2C.h>

#endif



PcfData::PcfData(QObject *parent) : QThread(parent)
  , m_fd(-1)
{
    initPcf();
}

PcfData::~PcfData()
{
#if PCF_TEST
    if(m_fd >= 0){

    }

#endif

}

void PcfData::initPcf()
{

#if PCF_TEST
    wiringPiSetup();
    //m_fd = wiringPiI2CSetup(PCF_ADDRESS);
    m_fd = pcf8591Setup(PCF,PCF_ADDRESS);
#endif
    QString logStr= typeid(this).name()+QString(" %1").arg( __func__) +" -- "+ QString("%1").arg( __LINE__)  +" contents ="+" m_fd=="+QString::number(m_fd);
    PrintLog::gestance()->printInfor(logStr);
}

PcfData *PcfData::gestance()
{
    static PcfData   pcfData;

    return  &pcfData;
}

int PcfData::readPcf(int channel)
{
    int value =0;
#if PCF_TEST
//    wiringPiI2CWriteReg8(m_fd, channel+1, 1);
//    delay(1);
//    value = wiringPiI2CReadReg8(m_fd, channel+1);
    value = analogRead(channel);
#endif
    return value;
}

void PcfData::run()
{

}
